/**
 * 统计[s1, s2]之间数位和在[min,max]之间的数字串 
 * s2在1E22, max在400，所以设 D[25][401] 即可
 * 要实现字符串的减一操作
 */
using llt = long long;
llt const MOD = 1E9 + 7;
int Lower, Upper;

vector<int> G;
llt D[25][401];
llt dfs(int pos, int sum, bool lead, bool limit){
    if(-1 == pos) { 
        return Lower <= sum and sum <= Upper ? 1 : 0;
    }
    if(not lead and not limit and -1 != D[pos][sum]) {
        return D[pos][sum];
    }
    int last = limit ? G[pos] : 9;
    llt ans = 0;
    for(int i=0;i<=last;++i){
        auto tmp = sum + i;
        if(tmp > Upper) continue;
        // 注意小于的话不能continue
        ans += dfs(pos - 1, tmp, lead&&0==i, limit&&last==i);
        ans %= MOD;          
    }
    if(not lead and not limit){
        D[pos][sum] = ans;
    }    
    return ans;
}

// 字符串减一
void dec(string & s){
    int k = s.size() - 1;
    while(s[k] == '0') --k;
    s[k] -= 1;
    for(int i=k+1;i<s.size();++i) s[i] = '9';
    return;
}

llt digitDP(const string & s){
    G.clear();
    for(auto c : s) G.emplace_back(c - '0');
    reverse(G.begin(), G.end());
    return dfs(G.size()-1, 0, true, true);
}

class Solution {
public:
    int count(string num1, string num2, int min_sum, int max_sum) {
        Lower = min_sum, Upper = max_sum;
        memset(D, -1, sizeof(D));
        dec(num1);
        auto t1 = digitDP(num1);
        auto t2 = digitDP(num2);
        return ((t2 - t1) % MOD + MOD) % MOD;
    }
};